blob: c6f073cea42a2a91fba1aeb17505fe6cd7f46ac8 [file] [log] [blame]
Junio C Hamanoff4b4312006-10-25 22:55:311git-for-each-ref(1)
2===================
3
4NAME
5----
6git-for-each-ref - Output information on each ref
7
8SYNOPSIS
9--------
Junio C Hamanoa9b8d242007-05-19 04:51:5510[verse]
Junio C Hamanofce7c7e2008-07-02 03:06:3811'git for-each-ref' [--count=<count>] [--shell|--perl|--python|--tcl]
Junio C Hamanod2179ef2010-10-22 04:12:1712 [(--sort=<key>)...] [--format=<format>] [<pattern>...]
Junio C Hamano1eb56092015-10-05 20:39:5313 [--points-at <object>] [(--merged | --no-merged) [<object>]]
14 [--contains [<object>]]
Junio C Hamanoff4b4312006-10-25 22:55:3115
16DESCRIPTION
17-----------
18
19Iterate over all refs that match `<pattern>` and show them
20according to the given `<format>`, after sorting them according
Junio C Hamanoa2f46622008-09-03 05:20:3121to the given set of `<key>`. If `<count>` is given, stop after
Junio C Hamanof9771f62007-01-17 17:42:3022showing that many refs. The interpolated values in `<format>`
Junio C Hamanoff4b4312006-10-25 22:55:3123can optionally be quoted as string literals in the specified
24host language allowing their direct evaluation in that language.
25
26OPTIONS
27-------
28<count>::
29By default the command shows all refs that match
30`<pattern>`. This option makes it stop after showing
31that many refs.
32
33<key>::
34A field name to sort on. Prefix `-` to sort in
35descending order of the value. When unspecified,
Junio C Hamanof7c042d2008-06-06 22:50:5336`refname` is used. You may use the --sort=<key> option
37multiple times, in which case the last key becomes the primary
38key.
Junio C Hamanoff4b4312006-10-25 22:55:3139
40<format>::
41A string that interpolates `%(fieldname)` from the
42object pointed at by a ref being shown. If `fieldname`
43is prefixed with an asterisk (`*`) and the ref points
44at a tag object, the value for the field in the object
45tag refers is used. When unspecified, defaults to
Junio C Hamano4de43af2006-10-28 21:29:0146`%(objectname) SPC %(objecttype) TAB %(refname)`.
47It also interpolates `%%` to `%`, and `%xx` where `xx`
48are hex digits interpolates to character with hex code
49`xx`; for example `%00` interpolates to `\0` (NUL),
50`%09` to `\t` (TAB) and `%0a` to `\n` (LF).
Junio C Hamanoff4b4312006-10-25 22:55:3151
Junio C Hamano9e395072008-07-31 22:11:2152<pattern>...::
Junio C Hamanof7c042d2008-06-06 22:50:5353If one or more patterns are given, only refs are shown that
Junio C Hamanocb1c44f2008-08-06 06:19:3354match against at least one pattern, either using fnmatch(3) or
Junio C Hamanof7c042d2008-06-06 22:50:5355literally, in the latter case matching completely or from the
56beginning up to a slash.
Junio C Hamanoff4b4312006-10-25 22:55:3157
Junio C Hamanoeb415992008-06-08 22:49:4758--shell::
59--perl::
60--python::
61--tcl::
Junio C Hamanoff4b4312006-10-25 22:55:3162If given, strings that substitute `%(fieldname)`
63placeholders are quoted as string literals suitable for
64the specified host language. This is meant to produce
65a scriptlet that can directly be `eval`ed.
66
Junio C Hamano1eb56092015-10-05 20:39:5367--points-at <object>::
68Only list refs which points at the given object.
69
70--merged [<object>]::
71Only list refs whose tips are reachable from the
72specified commit (HEAD if not specified).
73
74--no-merged [<object>]::
75Only list refs whose tips are not reachable from the
76specified commit (HEAD if not specified).
77
78--contains [<object>]::
79Only list tags which contain the specified commit (HEAD if not
80specified).
Junio C Hamanoff4b4312006-10-25 22:55:3181
82FIELD NAMES
83-----------
84
85Various values from structured fields in referenced objects can
86be used to interpolate into the resulting output, or as sort
87keys.
88
89For all objects, the following names can be used:
90
91refname::
Junio C Hamano42f855f2007-02-06 00:09:3892The name of the ref (the part after $GIT_DIR/).
Junio C Hamano5e4d8de2008-09-19 06:27:0293For a non-ambiguous short name of the ref append `:short`.
Junio C Hamano3bd66e92009-04-18 06:17:5694The option core.warnAmbiguousRefs is used to select the strict
95abbreviation mode.
Junio C Hamanoff4b4312006-10-25 22:55:3196
97objecttype::
98The type of the object (`blob`, `tree`, `commit`, `tag`).
99
100objectsize::
Junio C Hamano1aa40d22010-01-21 17:46:43101The size of the object (the same as 'git cat-file -s' reports).
Junio C Hamanoff4b4312006-10-25 22:55:31102
103objectname::
104The object name (aka SHA-1).
Junio C Hamanoe97d5772010-05-19 08:13:58105For a non-ambiguous abbreviation of the object name append `:short`.
Junio C Hamanoff4b4312006-10-25 22:55:31106
Junio C Hamano98e32c32009-04-13 02:39:53107upstream::
108The name of a local ref which can be considered ``upstream''
109from the displayed ref. Respects `:short` in the same way as
Junio C Hamanof079f702013-12-06 23:43:18110`refname` above. Additionally respects `:track` to show
111"[ahead N, behind M]" and `:trackshort` to show the terse
112version: ">" (ahead), "<" (behind), "<>" (ahead and behind),
113or "=" (in sync). Has no effect if the ref does not have
114tracking information associated with it.
115
Junio C Hamano975f4db2015-06-05 20:28:29116push::
117The name of a local ref which represents the `@{push}` location
118for the displayed ref. Respects `:short`, `:track`, and
119`:trackshort` options as `upstream` does. Produces an empty
120string if no `@{push}` ref is configured.
121
Junio C Hamanof079f702013-12-06 23:43:18122HEAD::
123'*' if HEAD matches current ref (the checked out branch), ' '
124otherwise.
125
126color::
127Change output color. Followed by `:<colorname>`, where names
128are described in `color.branch.*`.
Junio C Hamano98e32c32009-04-13 02:39:53129
Junio C Hamano1eb56092015-10-05 20:39:53130align::
131Left-, middle-, or right-align the content between
132%(align:...) and %(end). The "align:" is followed by `<width>`
133and `<position>` in any order separated by a comma, where the
134`<position>` is either left, right or middle, default being
135left and `<width>` is the total length of the content with
136alignment. If the contents length is more than the width then
137no alignment is performed. If used with '--quote' everything
138in between %(align:...) and %(end) is quoted, but if nested
139then only the topmost level performs quoting.
140
Junio C Hamanoff4b4312006-10-25 22:55:31141In addition to the above, for commit and tag objects, the header
142field names (`tree`, `parent`, `object`, `type`, and `tag`) can
143be used to specify the value in the header field.
144
145Fields that have name-email-date tuple as its value (`author`,
146`committer`, and `tagger`) can be suffixed with `name`, `email`,
147and `date` to extract the named component.
148
Junio C Hamano8fb66e52011-10-05 20:59:51149The complete message in a commit and tag object is `contents`.
Junio C Hamano281fd392012-09-17 23:57:41150Its first line is `contents:subject`, where subject is the concatenation
151of all lines of the commit message up to the first blank line. The next
152line is 'contents:body', where body is all of the lines after the first
Junio C Hamano1eb56092015-10-05 20:39:53153blank line. The optional GPG signature is `contents:signature`. The
154first `N` lines of the message is obtained using `contents:lines=N`.
Junio C Hamanoff4b4312006-10-25 22:55:31155
156For sorting purposes, fields with numeric values sort in numeric
157order (`objectsize`, `authordate`, `committerdate`, `taggerdate`).
158All other fields are used to sort in their byte-value order.
159
Junio C Hamano1eb56092015-10-05 20:39:53160There is also an option to sort by versions, this can be done by using
161the fieldname `version:refname` or its alias `v:refname`.
162
Junio C Hamanoff4b4312006-10-25 22:55:31163In any case, a field name that refers to a field inapplicable to
164the object referred by the ref does not cause an error. It
165returns an empty string instead.
166
Junio C Hamano1b50ce92007-10-03 12:05:53167As a special case for the date-type fields, you may specify a format for
Junio C Hamano1eb56092015-10-05 20:39:53168the date by adding `:` followed by date format name (see the
169values the `--date` option to linkgit::git-rev-list[1] takes).
Junio C Hamano1b50ce92007-10-03 12:05:53170
Junio C Hamanoff4b4312006-10-25 22:55:31171
172EXAMPLES
173--------
174
175An example directly producing formatted text. Show the most recent
Junio C Hamanoa8cc1d82011-03-10 01:18:121763 tagged commits:
Junio C Hamanoff4b4312006-10-25 22:55:31177
178------------
179#!/bin/sh
180
Junio C Hamanofce7c7e2008-07-02 03:06:38181git for-each-ref --count=3 --sort='-*authordate' \
Junio C Hamanoff4b4312006-10-25 22:55:31182--format='From: %(*authorname) %(*authoremail)
183Subject: %(*subject)
184Date: %(*authordate)
185Ref: %(*refname)
186
187%(*body)
188' 'refs/tags'
189------------
190
191
192A simple example showing the use of shell eval on the output,
Junio C Hamanoa8cc1d82011-03-10 01:18:12193demonstrating the use of --shell. List the prefixes of all heads:
Junio C Hamanoff4b4312006-10-25 22:55:31194------------
195#!/bin/sh
196
Junio C Hamanofce7c7e2008-07-02 03:06:38197git for-each-ref --shell --format="ref=%(refname)" refs/heads | \
Junio C Hamanoff4b4312006-10-25 22:55:31198while read entry
199do
200eval "$entry"
201echo `dirname $ref`
202done
203------------
204
205
206A bit more elaborate report on tags, demonstrating that the format
Junio C Hamanoa8cc1d82011-03-10 01:18:12207may be an entire script:
Junio C Hamanoff4b4312006-10-25 22:55:31208------------
209#!/bin/sh
210
211fmt='
212r=%(refname)
213t=%(*objecttype)
214T=${r#refs/tags/}
215
216o=%(*objectname)
217n=%(*authorname)
218e=%(*authoremail)
219s=%(*subject)
220d=%(*authordate)
221b=%(*body)
222
223kind=Tag
224if test "z$t" = z
225then
226# could be a lightweight tag
227t=%(objecttype)
228kind="Lightweight tag"
229o=%(objectname)
230n=%(authorname)
231e=%(authoremail)
232s=%(subject)
233d=%(authordate)
234b=%(body)
235fi
236echo "$kind $T points at a $t object $o"
237if test "z$t" = zcommit
238then
239echo "The commit was authored by $n $e
240at $d, and titled
241
242 $s
243
244Its message reads as:
245"
246echo "$b" | sed -e "s/^/ /"
247echo
248fi
249'
250
Junio C Hamanofce7c7e2008-07-02 03:06:38251eval=`git for-each-ref --shell --format="$fmt" \
Junio C Hamanoff4b4312006-10-25 22:55:31252--sort='*objecttype' \
253--sort=-taggerdate \
254refs/tags`
255eval "$eval"
256------------
Junio C Hamanoa8cc1d82011-03-10 01:18:12257
Junio C Hamanofd98be82014-01-22 22:45:38258SEE ALSO
259--------
260linkgit:git-show-ref[1]
261
Junio C Hamanoa8cc1d82011-03-10 01:18:12262GIT
263---
264Part of the linkgit:git[1] suite